var models = require('../models');
var url = require('url')

/**
 * Created by banzhenyu on 2016/10/28.
 * 网页端调用verson控制器的拦截器,用来过滤非法请求
 */
var functions = {

    apiAuthFilter: function (req, res, next) {
        if (req.query.hasOwnProperty('tk')) { //其他接口都需要认证后才能访问
            var token = req.query.tk;
            if (models.tokenCache.exists(token)) {
                next();
            } else {
                res.status(401).send({code: 1, message: "Unauthorized!"});
            }
        } else {
            res.status(401).send({code: 1, message: "Unauthorized!"});
        }
    },

}

module.exports = functions;